import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:张熳
 * Date:2025-11-26
 * Time:22:07
 */
public class Test {
    public static void orderArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            //array[i] = i; //升序
            array[i] = array.length-1-i; //逆序
        }
    }
    public static void notOrderArray(int[] array) {
        //生成随机数数组
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }
    //测试简单数据能否执行，测试算法是否正确
    public static void testSimple() {
        int[] array = {91,1,2,5,7,4,81,6,3,5,15,89,43};
        System.out.println("排序前："+ Arrays.toString(array));
        //Sort.insetSort(array);
        //Sort.shellSort(array);
        //Sort.selectSort(array);
        //Sort.heapSort(array);
        //Sort.bubbleSort(array);
        Sort.quickSort(array);
        System.out.println("排序后："+Arrays.toString(array));
    }

    public static void testInsert(int[] array) {
        array = Arrays.copyOf(array,array.length);//排序前先拷贝一份放到新的array数组中，就不会动用原数组，排好序的是新数组，原数组不变
        long startTime = System.currentTimeMillis();
        Sort.insetSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序耗时"+(endTime-startTime)+"毫秒");
    }

    public static void testShell(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序耗时"+(endTime-startTime)+"毫秒");
    }

    public static void testSelect(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接选择排序耗时"+(endTime-startTime)+"毫秒");
    }

    public static void testHeap(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序耗时"+(endTime-startTime)+"毫秒");
    }

    public static void testBubble(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.bubbleSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序耗时"+(endTime-startTime)+"毫秒");
    }

    public static void testQuick(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序耗时"+(endTime-startTime)+"毫秒");
    }

    public static void testOrder() {
        int[] array = new int[10_0000];
        orderArray(array);
        //notOrderArray(array);
        testInsert(array);
        testShell(array);
        testSelect(array);
        testHeap(array);
        testBubble(array);
        testQuick(array);
    }

    public static void main(String[] args) {
        //testSimple();
        testOrder();
    }
}
